<%--
  Created by IntelliJ IDEA.
  User: 27056
  Date: 2022/7/1
  Time: 14:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>商品信息</title>
    <script src="js/jquery-1.8.3.js"></script>
    <script>
        $(document).ready(function (){
            $("tr:even").css("background-color","aqua");
            $("tr:eq(0)").css("background-color","pink","font-weight","bold");
            $("#flag").find("option[value='${requestScope.flag}']").attr("selected",true)
        })

    </script>

</head>
<body>
    <h1 style="text-align: center">元宇宙商品信息列表</h1>
    <form action="metaverseProductListServlet?pageIndex=1" method="post" style="margin-left: 630px">
    商品名称：
    <input type="text" id="name" name="name" value="${requestScope.name}">
    状态：
    <select id="flag" name="flag">
        <option value="2"></option>
        <option value="1">上架</option>
        <option value="0">下架</option>
    </select>
        <input type="submit" value="查询">
    </form>
    <table border="1" style="text-align: center;margin: 0px auto">
        <tr>
            <td>编号</td>
            <td>名称</td>
            <td>描述</td>
            <td>价格</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${requestScope.list}" var="metaverseProduct">
            <tr>
                <td>${metaverseProduct.id}</td>
                <td>${metaverseProduct.name}</td>
                <td>${metaverseProduct.desc}</td>
                <td>${metaverseProduct.price}</td>
                <td><c:if test="${metaverseProduct.flag==0}">下架</c:if> <c:if test="${metaverseProduct.flag==1}">上架</c:if></td>
                <td><a href="" onclick="upda(${metaverseProduct.id},${metaverseProduct.flag})">修改</a><a href="" onclick="del(${metaverseProduct.id})">删除</a></td>
            </tr>
        </c:forEach>
    </table>
    <div style="margin-left:800px;margin-top: 10px"><c:if test="${requestScope.pageIndex!=1}">
        <a href="metaverseProductListServlet?pageIndex=${requestScope.pageIndex-1}&name=${requestScope.name}&flag=${requestScope.flag}">上一页</a>
    </c:if>
    <a href="metaverseProductListServlet?pageIndex=1&name=${requestScope.name}&flag=${requestScope.flag}">首页</a>
    <a href="metaverseProductListServlet?pageIndex=${requestScope.pageIndex+1}&name=${requestScope.name}&flag=${requestScope.flag}">下一页</a>
    </div>
    <a style="margin-left: 650px" href="metaverseProductAdd.jsp">新增元宇宙商品</a>
</body>
<script>
    function del(id){
        if(confirm('确定要删除嘛?')){
            $.get("metaverseProductDelServlet","id="+id,function (data){
                if(data=="true"){
                    alert("删除成功!");
                }else{
                    alert("删除失败!");
                }
                window.location="metaverseProductListServlet";
            })
        }
    }
    function upda(id,flag){
        if(flag==1?confirm("确定下架嘛?"):confirm("确定要上架嘛")){
            $.get("metaverseProductUpdateServlet","id="+id+"&flag="+flag,function (data){
                if(data=="true"){
                    alert("修改成功!");
                }else{
                    alert("修改失败!");
                }
                window.location="metaverseProductListServlet";
            })
        }
    }
</script>
</html>
